/*
 * Player.java
 *
 * Copyright(c) 2009 - Kimnach
 * See Main.java for copyright notice.
 *
 */

package player;

import java.awt.Color;
import java.util.ArrayList;
import java.util.HashMap;
import monster.Monster;

/**
 * Player class
 * @author dkimnach
 */
public class Player {
    private int health; // unused
    private int prestige; // unused
    private String name;
    private Color col;
    private ArrayList<Monster> miniMon = new ArrayList<Monster>(); // Boogen or Wolfpack
    private HashMap<String, Monster> kills = new HashMap<String, Monster>();

    // states
    boolean dead;

    // interesting stats
    private int lostTurns;
    private ArrayList<Integer> initiatives = new ArrayList<Integer>(); // initiatives dealt
    private int halved; // how many times damage halved due to monster attacks

    /**
     * Constructs a new <code>Player</code> with [name] and [color]
     * @param name
     * @param col color
     */
    public Player(String name, Color col) {
        this.name = name;
        health = 100;
        prestige = 0;
        dead = false;
        this.col = col;
    }
    
    /**
     * Award prestige
     * @param pres prestige to award for kill
     * @return current prestige
     */
    public int addPrestige(int pres) {
        prestige += pres;
        return prestige;
    }
    
    /**
     * Deduct prestige
     * @param pres prestige to deduct for losing a kill
     * @return current prestige
     */
    public int removePrestige(int pres) {
        prestige += pres;
        return prestige;
    }
    
    /**
     * Take damage
     * @param dmg damage
     * @return current health
     */
    public int damage(int dmg) {
        health -= dmg;
        if (health <= 0) {
            health = 0;
            this.die();
        }
        return health;
    }
    
    /**
     * Heals a player
     * @param heal amount to heal player
     * @return current health
     */
    public int heal(int heal) {
        health += heal;
        if (health > 100) { health = 100; }
        return health;
    }

    /**
     * Kill player
     */
    public void die() {
        dead = true;
    }

    /**
     * Revive player
     */
    public void revive() {
        dead = false;
    }

    /**
     * Check if dead
     * @return if dead
     */
    public boolean isDead() {
        return dead;
    }

    /**
     * Get current health
     * @return health
     */
    public int getHealth() {
        return health;
    }

    /**
     * Get player color
     * @return color
     */
    public Color getColor() {
        return col;
    }

    /**
     * Get current prestige
     * @return prestige
     */
    public int getPrestige() {
        return prestige;
    }

    /**
     * Get player name
     * @return name
     */
    public String getName() {
        return name;
    }

    @Override
    public String toString() {
        String player = name + "\n";
        player += "Lost " + lostTurns + " turns\n" ;
        //player += "Damage was halved " + halved + " times due to monster attacks\n";


        player += "Dealt Initiatives:\n";
        int ones = 0;
        int twos = 0;
        int threes = 0;
        int fours = 0;
        int fives = 0;
        int sixes = 0;
        for (int init : initiatives) {
            if (init == 1) {
                ones++;
            } else if (init == 2) {
                twos++;
            } else if (init == 3) {
                threes++;
            } else if (init == 4) {
                fours++;
            } else if (init == 5) {
                fives++;
            } else {
                sixes ++;
            }
        }
        player += "\t* " + ones + " ones\n";
        player += "\t* " + twos + " twos\n";
        player += "\t* " + threes + " threes\n";
        player += "\t* " + fours + " fours\n";
        player += "\t* " + fives + " fives\n";
        player += "\t* " + sixes + " sixes\n";

        return player;
    }

    /**
     * Add a mini monster in front of the player
     * @param type name of monster type (boogen or wolf)
     * @param num number of mini monsters
     * @param prestige amount of prestige
     * @return monster array
     */
    public ArrayList<Monster> addMinis(String type, int num, int prestige) {
        for (int i = 0; i < num; i++) {
            miniMon.add(new Monster(type, Monster.MINI_HEALTH, prestige)); // wolfpack
        }
        return miniMon;
    }

    /**
     * Damage a mini montster in front of the player
     * @param index
     * @param dmg damage
     * @return health of mini
     */
    public int dmgMini(int index, int dmg) {
        int h = miniMon.get(index).damage(dmg);

        return h;
    }

    /**
     * Mini monster killed
     * @param index
     * @return mini monster prestige
     */
    public int killMini(int index) {
        Monster m = miniMon.remove(index);
        
        return m.getPrestige();
    }

    /**
     * Get mini monster prestige
     * @param index
     * @return mini monster prestige
     */
    public int getMiniPres(int index) {
        int p = miniMon.get(index).getPrestige();
        
        return p;
    }

    /**
     * Get mini monster health
     * @param index
     * @return mini monster health
     */
    public int getMiniHealth(int index) {
        int h = miniMon.get(index).getHealth();
        return h;
    }

    /**
     * Returns the number of mini monsters in front of player
     * @return mini monsters
     */
    public int getMiniCount() {
        return miniMon.size();
    }

    public void setName(String name) {
        this.name = name;
    }

    
}
